package com.tongzhan.controller;

import com.tongzhan.base.Return;
import com.tongzhan.service.StreetService;
import com.tongzhan.vo.StreetVO;
import com.tongzhan.vo.VillageVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/system")
public class SystemController {

    @Resource
    private StreetService streetService;


    /**
     * 获取街道列表接口
     *
     * @return Return
     */
    @GetMapping("/getStreetList")
    public Return getStreetList() {
        List<StreetVO> streetVOS = streetService.getStreetList();
        Map<String, Object> map = new HashMap<>();
        map.put("streetList", streetVOS);
        return new Return(map);
    }


    @PostMapping("/getVillageList")
    public Return getVillageList(String streetCode) {
        if (StringUtils.isEmpty(streetCode)) {
            return new Return(Return.MISS_PARAM, "参数缺失");
        }
        List<VillageVO> villageVOS = streetService.getVillageList(streetCode);
        Map<String, Object> map = new HashMap<>();
        map.put("villageList", villageVOS);
        return new Return(map);
    }

}
